// pages/meinu/meinu.js
const app=getApp()
Page({
  data:{
    show:true
  },
  initiatePayment: function () {
    console.log("点击支付");
    console.log(app.globalData.usercode)
    const that = this;
    
    wx.request({
      url: 'https://www.aistomatology.cn/wx/getPayParams',
      method: 'POST',
      header:{  
        'content-type':'application/x-www-form-urlencoded'
      },
      data: {
        code: app.globalData.usercode,
      },
      success: function (res) {
        console.log(res.data)
        const payParams = res.data.payParams;
        that.wxPay(payParams);
      },
      fail: function (error) {
        console.error('Failed to get payment parameters:', error);
      }
    });
  }, 
  wxPay: function (payParams) {
    var that=this
    wx.requestPayment({
      timeStamp: payParams.timeStamp,
      nonceStr: payParams.nonceStr,
      package: payParams.package,
      signType: payParams.signType,
      paySign: payParams.paySign,
      success: function (res) {
        console.log('Payment success:', res);
        that.setData({
          show:"none"
        })
        // 处理支付成功的逻辑
      },
      fail: function (error) {
        console.log(payParams)
        console.error('Payment failed:', error);
        // 处理支付失败的逻辑
      }
    });
  },
  onShareAppMessage() {

  }
})